package com.pro.xwt.common.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pro.xwt.common.example.BMessageExample;
import com.pro.xwt.common.mapper.BMessageMapper;
import com.pro.xwt.common.mapper.BTaskMapper;
import com.pro.xwt.common.model.BMessage;
import com.pro.xwt.common.model.BTask;
import com.pro.xwt.common.service.BMessageService;
import com.pro.xwt.common.utils.Common;
@Service("bMessageService")
public class BMessageServiceImpl extends AbstractService<BMessage, String> implements BMessageService {

	@Autowired
	BMessageMapper dao;
	@Autowired
	BTaskMapper bTaskMapper;
	
	@Override
	public List<BMessageExample> selectAll(Map<String, Object> parameter) {
		// TODO Auto-generated method stub
		return dao.selectAll(parameter);
	}

	@Override
	public int insertMessage(List<BTask> bTask) {
		for (BTask bTask2 : bTask) {
			BTask bT = new BTask();
			BMessage bm = new BMessage();
			String content ="你有一个任务已经逾期，请尽快处理";
			bm.setId(Common.generateUUID());
			bm.setContent(content);
			bm.setType("OVERTIME");
			bm.setReadState("0");
			bm.setTaskId(bTask2.getId());
			bm.setAccpEmpId(bTask2.getExecEmpId());
			bm.setExpireTime(bTask2.getLastEndTime());
			bm.setCreateTime(new Date());
			bm.setDeleteState("0");
			bm.setCreateEmpId(bTask2.getCreateEmpId());
			dao.insert(bm);
			bT.setMsgState("1");
			bT.setId(bTask2.getId());
			bTaskMapper.update(bT);
		}
		return 0;
	}

}
